import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
import { MessageService } from '../../../core/service';
import { LayoutRourteStatus } from 'src/app/model/status';
import { Router } from '@angular/router';

@Component({
    selector: 'app-menu2',
    templateUrl: './menu2.component.html',
    styleUrls: ['./menu2.component.scss']
})
export class Menu2Component implements OnInit {

    url: string;

    @Input()
    isCollapsed: boolean;


    mode = false;
    dark = false;
    menus = [
        {
            'level': 1,
            'title': '账户中心',
            'icon': 'user',
            'url': '/member/center/account/info',
            'open': true,
            'selected': false,
            'disabled': false,
        }, {
            'level': 1,
            'title': '安全设置',
            'icon': 'setting',
            'url': '/member/center/account/setting',
            'open': false,
            'selected': false,
            'disabled': false,
        }
    ];
    constructor(
        private router: Router,
        private msg: MessageService
    ) { }

    ngOnInit() {
        this.msg.getMessage().subscribe((e: LayoutRourteStatus) => {
            for (let i = 0; i < this.menus.length; i++) {
                console.log(e);
                if (this.menus[i].url === e.manu2Url) {
                    this.menus[i].selected = true;
                } else {
                    this.menus[i].selected = false;
                }
            }
        });
    }

    public onClick(item): void {
        console.log(item);
        item.disabled ? null : this.gotoNextPage(item);
    }
    public gotoNextPage(item): void {
        this.router.navigate([item.url]);
    }

}
